/*
 * @Author: your name
 * @Date: 2021-01-21 15:12:27
 * @LastEditTime: 2021-01-28 10:33:37
 * @FilePath: \flutter_study\lib\pages\list_demo.dart
 */
import 'package:flutter/material.dart';
import '../mock/posts.dart';
import './router_demo.dart'; // 路由模块

class ListViewDemo extends StatefulWidget {
  @override
  _ListViewDemoState createState() => _ListViewDemoState();
}

class _ListViewDemoState extends State<ListViewDemo> {
  Widget _listViewItemBuilder(BuildContext context, int index) {
    return InkWell(
      child: Container(
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(4.0), color: Colors.white),
        margin: EdgeInsets.all(10.0),
        child: Column(
          children: <Widget>[
            Image.network(
              posts[index].imageUrl,
              fit: BoxFit.fitWidth,
            ),
            SizedBox(
              height: 16.0,
            ),
            Text(posts[index].title),
            Text(posts[index].author),
            SizedBox(
              height: 16.0,
            )
          ],
        ),
      ),
      onTap: () {
        Navigator.of(context).push(MaterialPageRoute(
            builder: (context) => PageDetailDemo(
                  post: posts[index],
                )));
      },
    );

    // Stack(
    //   children: <Widget>[
    //     Container(
    //       decoration: BoxDecoration(
    //           borderRadius: BorderRadius.circular(4.0), color: Colors.white),
    //       margin: EdgeInsets.all(10.0),
    //       child: Column(
    //         children: <Widget>[
    //           Image.network(
    //             posts[index].imageUrl,
    //             fit: BoxFit.fitWidth,
    //           ),
    //           SizedBox(
    //             height: 16.0,
    //           ),
    //           Text(posts[index].title),
    //           Text(posts[index].author),
    //           SizedBox(
    //             height: 16.0,
    //           )
    //         ],
    //       ),
    //     ),
    //     Positioned.fill(
    //         child: Material(
    //       color: Colors.transparent,
    //       child: InkWell(
    //           splashColor: Colors.white.withOpacity(0.3),
    //           highlightColor: Colors.white.withOpacity(0.1),
    //           onTap: () {
    //             print(123);
    //           }),
    //     )),
    //   ],
    // );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.grey[100],
      child: ListView.builder(
        itemCount: posts.length,
        itemBuilder: _listViewItemBuilder,
      ),
    );
  }
}
